$(function() {
    $.ajaxPrefilter(function(options) {
        /* 配置请求头 */
        if (options.url.indexOf('/admin') == 0) {
            options.headers = {
                Authorization: localStorage.getItem('token') || ''
            }
        }
        options.url = 'http://localhost:8888' + options.url
        options.complete = function(res) {
            console.log(res);
            var res = res.responseJSON
                /* 判断是否认证失败 */
            if (res.status == 1 && res.message == '身份认证失败！') {
                /* 清除本地的token */
                localStorage.removeItem('token')
                    /* 跳转到登录页 */
                window.parent.location.href = '/login.html'
            }
        }
    });
})